<template>
    <div id="pulpTest">
         <!-- 查询 -->
        <el-popover placement="bottom-start" width="830" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
            <el-form :inline="true" :model="searchList" label-width="75px" class="demo-ruleForm">
                <el-form-item label="浆员卡号" style="margin-bottom: 0;"><el-input v-model="searchList.cardid" style="width: 100px;"></el-input></el-form-item>
                <el-form-item label="浆员姓名" style="margin-bottom: 0;"><el-input v-model="searchList.name" style="width: 100px;"></el-input></el-form-item>
                <el-form-item label="创建时间" style="margin-bottom: 0;"><el-date-picker v-model="searchList.time" type="daterange" style="width: 300px;" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" align="right"></el-date-picker></el-form-item>
                <el-button type="primary" @click="searchData">提交</el-button>
            </el-form>
            <el-button slot="reference" type="primary">查询</el-button>
        </el-popover>
        <!-- 表格 -->
        <el-table :data="tableData" stripe border class="company-table" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable align="center" min-width="40"></el-table-column>
            <el-table-column prop="cardId" label="卡号" sortable min-width="90"></el-table-column>
            <el-table-column prop="providerNoName" label="姓名" sortable min-width="100"></el-table-column>
            <el-table-column prop="bodyCheckWorkerName" label="体检医生" sortable min-width="110"></el-table-column>
            <el-table-column prop="createNurseName" label="体检护士" sortable min-width="110"></el-table-column>
            <el-table-column prop="registerOrder" label="登记序号" sortable min-width="110"></el-table-column>
            <el-table-column prop="bodyCheckOrder" label="体检序号" sortable min-width="110"></el-table-column>
            <el-table-column prop="authMethod" label="认证方式" :formatter="formatterAuthMethod" sortable min-width="110"></el-table-column>
            <el-table-column prop="bodyStartTime" label="体检开始时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="recodeCreateTime" label="记录创建时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="recodeStatus" label="记录状态" :formatter="formatterIsRecode"  sortable min-width="110"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" min-width="75">
                <template slot-scope="scope">
                    <el-button  @click="updateDialog(scope.row)" type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[10, 15,20, 25,30,50, 100]" :page-size="pagination.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
        <!-- 详情 -->
        <el-dialog :title="dialog.title" :visible.sync="dialog.isShow" width="1100px" top="60px" :close-on-click-modal="false" >
            <div :style="dialog.dialogStyle">
                <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                <!-- 浆员基本信息 -->
                <pulpwork-info v-bind:cardid="dialogList.providerNo"></pulpwork-info>
                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>生命体征</span></h3>
                <el-form :inline="true" :model="dialogList" :rules="dialogRules" ref="dialogRules" label-width="120px" class="demo-ruleForm">
                        <el-form-item label="体重/kg" prop="weight"><el-input v-model="dialogList.weight"></el-input></el-form-item>
                        <el-form-item label="体温/℃" prop="animalHeat"><el-input v-model="dialogList.animalHeat"></el-input></el-form-item>
                        <el-form-item label="脉搏/B/M" prop="pulse"><el-input v-model="dialogList.pulse"></el-input></el-form-item>
                        <el-form-item label="血压/KPa">
                            <el-row style="width: 200px;">
                                <el-col :span="11"><el-form-item prop="lowBlood"><el-input  v-model="dialogList.lowBlood"></el-input></el-form-item></el-col>
                                <el-col class="line" :span="2">-</el-col>
                                <el-col :span="11"><el-form-item prop="highBlood"><el-input  v-model="dialogList.highBlood"></el-input></el-form-item></el-col>
                            </el-row>
                        </el-form-item>
                        <el-form-item label="体检护士"><el-input v-model="dialogList.createNurseName" disabled></el-input></el-form-item>
                </el-form>
                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>征询项目</span></h3>
                <el-row :gutter="20" style="margin-right: 0;" >
                    <el-col :span="8">
                        <el-row :gutter="20" style="margin-right: 0;" >
                            <el-col :span="12">
                                <el-upload class="avatar-uploader"
                                           ref="appendix"
                                           style="height: 230px;"
                                           :action="appendixUrl"
                                           :show-file-list="false"
                                           :on-success="handleAvatarSuccess"
                                           :before-upload="beforeAvatarUpload">
                                    <img v-if="dialogList.singlePhoto" :src="dialogList.singlePhoto" class="avatar" />
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-col>
                            <el-col :span="12">
                                <el-upload class="avatar-uploader"
                                           style="height: 230px;"
                                           :action="appendixUrl"
                                           :show-file-list="false"
                                           :on-success="handleAvatarSuccess1"
                                           :before-upload="beforeAvatarUpload"
                                >
                                    <img v-if="dialogList.singlePhoto1" :src="dialogList.singlePhoto1" class="avatar" />
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col :span="16">
                        <el-form :inline="true" :model="dialogList" label-width="100px" class="demo-ruleForm">
                            <el-form-item label="上传时间"><el-input v-model="dialogList.singleUploadTime" ></el-input></el-form-item>
                            <el-form-item label="胸部"><el-select v-model="dialogList.chest" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="腹部"><el-select v-model="dialogList.abdomen"  ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="皮肤"><el-select v-model="dialogList.skin"  ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="五官"><el-select v-model="dialogList.facial" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="四肢"><el-select v-model="dialogList.limbs" ><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="健康征询"><el-select v-model="dialogList.healthSingle"><el-option :value="1" label="是"></el-option><el-option :value="0" label="否"></el-option></el-select></el-form-item>
                            <el-form-item label="体检结果"><el-select v-model="dialogList.bodyCheckResult"><el-option value="" label="[空]"></el-option><el-option :value="0" label="不合格"></el-option><el-option :value="1" label="合格"></el-option><el-option :value="2" label="复检"></el-option></el-select></el-form-item>
                            <el-form-item v-if="dialogList.bodyCheckResult=='0'" label="拒绝类型"><el-select v-model="dialogList.refuseType"><el-option :value="0" label="暂拒"></el-option><el-option :value="1" label="永拒"></el-option></el-select></el-form-item>
                            <el-form-item v-if="dialogList.refuseType=='0'" label="暂拒原因"><el-input v-model="dialogList.outReason"></el-input></el-form-item>
                            <el-form-item v-if="dialogList.refuseType=='1'" label="永拒原因"><el-select v-model="dialogList.refuseReason"><el-option v-for="item in codeData2" :key="item.code" :value="item.code" :label="item.name"></el-option></el-select></el-form-item>
                            <el-form-item label="体检医生"><el-select v-model="dialogList.bodyCheckWorkerName" @change="changeWorker"><el-option v-for="item in dictorData" :key="item.id" :value="item.id" :label="item.name"></el-option></el-select></el-form-item>
                        </el-form>
                    </el-col>
                </el-row>
                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>其他</span></h3>
                <el-form :inline="true" :model="dialogList" label-width="120px" class="demo-ruleForm">
                    <el-form-item label="献浆人"><el-input v-model="dialogList.contributionPerson" disabled></el-input></el-form-item>
                    <el-form-item label="登记序号"><el-input v-model="dialogList.registerOrder" disabled></el-input></el-form-item>
                    <el-form-item label="体检编号"><el-input v-model="dialogList.bodyCheckNo" disabled></el-input></el-form-item>
                    <el-form-item label="体检序号"><el-input v-model="dialogList.bodyCheckOrder" disabled></el-input></el-form-item>
                    <el-form-item label="体检开始时间"><el-input v-model="dialogList.bodyStartTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录创建时间"><el-input v-model="dialogList.recodeCreateTime" disabled></el-input></el-form-item>
                    <el-form-item label="体检结束时间"><el-input v-model="dialogList.bodyEndTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录结束时间"><el-input v-model="dialogList.recodeEndTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录状态"><el-select v-model="dialogList.recodeStatus" disabled><el-option :value="0" label="待处理"></el-option><el-option :value="1" label="已处理"></el-option></el-select></el-form-item>
                </el-form>
            </div>
            <div slot="footer">
                <el-button type="primary" @click="submitDialog" >提交</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import api from '@/axios/api.js';
import regx from '@/regx/regx.js';
import pulpworkInfo from 'operationManage/components/pulpworkInfo.vue'
export default {
    name: "pulpTest",
    components:{
        pulpworkInfo
    },
    data(){
        return {
            loading:false,
            //分页相关参数
            pagination:{
                currentPage:1,
                pageSize:10,
                total:0
            },
            tableHeight: document.documentElement.clientHeight - 160,
            tableData:[],
            searchList:{// 查询
                name:'',
                cardid:'',
                time:'',
                bigCreateTime:'',
                lessCreateTime:''
            },
            codeData2:[],//
            createNurseName:[],/**护士列表 */
            dictorData:[],/**医生列表 */
            dialogList:{},
            isDialog:false,//详情
            dialog:{
                title:'',
                isShow:false,
                dialogStyle: {
                    height: document.documentElement.clientHeight - 230+ 'px',
                    overflowY: 'auto',
                }
            },
            appendixUrl:"/api/adscm/filesystem/abc",
            dialogRules:{
                 weight: [
                        { required: true, message: '请输入体重...', trigger: 'blur' },
                        {  type: 'number', message: '体重不能高于150Kg，低于45Kg', trigger: 'blur', validator:regx.validateWeight},
                    ],
                    animalHeat: [
                        { required: true, message: '请输入体温...', trigger: 'blur' },
                        { type: 'number', message: '体重不能高于37.2 ℃，低于36.3 ℃', trigger: 'blur',validator:regx.validateAnimalHeat }
                    ],
                    pulse: [
                        { required: true, message: '请输入脉搏...', trigger: 'blur' },
                        { type: 'number', message: '体重不能高于100/B/M，低于60/B/M', trigger: 'blur',validator:regx.validatePulse},
                    ],
                    lowBlood: [
                        { required: true, message: '请输入低血压...', trigger: 'blur' },
                        { type: 'number', message: '低压不能高于8/KPa，低于12/KPa', trigger: 'blur',validator:regx.validateLowBlood},
                    ],
                    highBlood: [
                        { required: true, message: '请输入高血压...', trigger: 'blur' },
                        { type: 'number', message: '高压不能高于12/KPa，低于20/KPa', trigger: 'blur',validator:regx.validateHighBlood},
                    ],
            }
        }
    },
    created(){
        let self =this;
        self.getData();
        api.getNurseData().then(res=>{
            self.createNurseName=res.content;
        })
        api.getDoctorData().then(res=>{
            self.dictorData=res.content;
        })
        api.getCodeData(2).then(res=>{})
    },
    methods:{
        getData(){//获取体检记录列表
            let self = this;
            self.loading=true;
            let list={
                name:self.searchList.name,
                cardid:self.searchList.cardid,
                recodeTime:self.timestampToTime(new Date).substr(0,10),
                bigCreateTime:self.timestampToTime( self.searchList.time[0]).substr(0,10),
                lessCreateTime:self.timestampToTime( self.searchList.time[1]).substr(0,10),
                pageSize:self.pagination.pageSize,
                currentPage:self.pagination.currentPage
            }
            api.bodyCheckTime(list).then(res=>{
                self.tableData=res.content.items;
                self.loading=false;
                self.pagination.total = res.content.total;
            },error=>{
                 self.loading=false;
            })
        },
        searchData(){
            this.pagination.currentPage=1;
            this.getData();
        },
        updateDialog(row){
            let self=this;
            self.dialog.title="详情信息";
            self.dialog.isShow=true;
            self.dialogList = row;
            self.dialogList.chest=(self.dialogList.chest===null?1:self.dialogList.chest);
            self.dialogList.abdomen=(self.dialogList.abdomen===null?1:self.dialogList.abdomen);
            self.dialogList.skin=(self.dialogList.skin===null?1:self.dialogList.skin);
            self.dialogList.facial=(self.dialogList.facial===null?1:self.dialogList.facial);
            self.dialogList.limbs=(self.dialogList.limbs===null?1:self.dialogList.limbs);
        },
        submitDialog(){//编辑详细信息
            let _this = this;
                delete this.dialogList['createNurseName'];
                delete this.dialogList['bodyCheckWorkerName'];
                api.bodyCheckUpdate(_this.dialogList).then(res=>{
                    _this.dialog.isShow = false;
                    _this.getData();
                });
        },
        handleSizeChange(size) {/**分页-每页显示尺寸 */
                this.pagination.currentPage=1;
                this.pagination.pageSize = size;
                this.getData();
            },
        handleCurrentChange(currentPage) {/**分页-跳转第几页 */
            this.pagination.currentPage = currentPage;
            this.getData();
        },
         // 头像上传
        handleAvatarSuccess(res, file,fileList) {
            console.log( res,file )
            this.dialogList.singlePhoto = res;
        },
        handleAvatarSuccess1(res, file) {
            this.dialogList.singlePhoto1 = res;
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type.substr(0,5) === 'image';
            const isLt1M = file.size / 1024 / 1024 < 1;
            if (!isJPG) {
                this.$message.error('只能上传图片!');
            }
            if (!isLt1M) {
                this.$message.error('上传头像图片大小不能超过 1MB!');
            }
            return isJPG && isLt1M;
        },
        changeWorker(value){/*更改体检医生 */
            this.dialogList.bodyCheckWorker=value;
        }
    }
}
</script>
<style>

</style>


